#ifndef GLOBAL_H
#define GLOBAL_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include <alsa/asoundlib.h>
#include <errno.h>
#include "memory.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avio.h"
#include "libavutil/avutil.h"
#include "libavutil/log.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavfilter/avfilter.h"
#include "libavutil/avstring.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/dict.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
#include "libswresample/swresample.h"
#include "libavutil/opt.h"
#include "libavcodec/avfft.h"
#include "libavutil/audioconvert.h"
#include "libavutil/mathematics.h"

#include "x264.h"
#include "xvid.h"
#include "zlib.h"
}

typedef struct _TREALMEDIA
{
    SEMAPHOREHANDLE semaphore_yuv, semaphore_coded;
    FIFOBUFFERHANDLE fifo_yuv, fifo_coded;
    AVFormatContext *pOutputFormatContext;
    AVStream *pOutputVideoStream;
    AVPacket outPacket;
    AVFrame *pVideoFrame;    //for fill yuv data
    SwsContext  *ptSwsContextV; //for swscale to yuv 420p planner
    uint8_t *yuv_buffer;    //alloc buffer to fill source yuv data
    uint8_t *yuv_sws_buffer;//alloc buffer to file yuv420p data
    unsigned long long frameNum;
}TRealMedia, *PRealMedia;


#define SDL_AUDIO_U8    0x0008
#define SDl_AUDIO_S8    0x8008
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SDL_AUDIO_S16 0x8010
#else
#define SDL_AUDIO_S16 0x9010
#endif

#define SDL_MAX_BUFFER_OF_SOUNDS (8 * 1024 * 1024)  //音频
#define UDP_MAX_DATA_BUFFER (8 * 1024 * 1024)   //数据缓冲区大小

#define _DEVICE_NAME "/dev/video0"
#define CLEAR(x) memset(&(x), 0, sizeof(x))
#define _CAPTURE_WIDTH 640
#define _CAPTURE_HEIGHT 480


extern void *ThreadVideoCapture(void *pVoid);
extern void *ThreadVideoEncode(void *pVoid);

extern int RtspServerInit();

#endif // GLOBAL_H
